<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
	
	protected function _initSession(){
		Zend_Session::start();
	}
	protected function _initDb(){
		
		//Lay du lieu tu application.ini
		$optionConfig 	= 	$this->getOptions();
		$optionResource =   $optionConfig['resources'];
		$dbOption		=   $optionResource['db'];

		//Chinh sua thong tin ket noi database
		$dbOption['params']['host'] 	= 'localhost';
		$dbOption['params']['username'] = 'root';
		$dbOption['params']['password'] = '';
		$dbOption['params']['dbname'] 	= 'book';
		
		//Khoi tao ket noi den database
		$adapter 		=   $dbOption['adapter'];
		$config			= 	$dbOption['params'];
		$db = Zend_Db::factory($adapter,$config);
		$db->setFetchMode(Zend_Db::FETCH_ASSOC);
		$db->query("SET NAMES 'utf8'");
		$db->query("SET CHARACTER SET 'utf8'");
		
		//Tao registry luu tru thong tin
		Zend_Registry::set('connectDb',$db);
		
		Zend_Db_Table::setDefaultAdapter($db);
		
		return $db;
	}
	
	protected function _initFrontcontroller(){
		$front = Zend_Controller_Front::getInstance();
		$front->addModuleDirectory(APPLICATION_PATH . '/modules');
		$front->setDefaultModule('default');
		$error = new Zend_Controller_Plugin_ErrorHandler(
							array('module'	=>'default',
								  'controller'=>'public',
								  'action'	=>'error',
								 ));
		
		//$front->registerPlugin($error);
		$front->registerPlugin(new Zendvn_Plugin_Permission());		
		return $front;
	} 
}